home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 47215 / 47215.xpi / chrome / content / js / _main.js
Text File  |  2009-11-22  |  3KB  |  87 lines

  1. (function()
  2. {
  3.             var debugingThisFile = false;//sets debuging on/off for this JavaScript file
  4.         //add the listeners
  5.             this.addListener('browserLoad', function(){URLtoTabTitle.URLtoTabTitleInit()});
  6.             //listeningn the actual tab
  7.             this.addListener('onLocationChange', function (aDoc){URLtoTabTitle.setTitleDoc(aDoc)});
  8.             //listeningn the documents loading in the background
  9.             this.addListener('DOMContentLoadedNoFrames', function (aDoc){URLtoTabTitle.setTitleDoc(aDoc)});
  10.  
  11.         //shutdown
  12.             this.addShutDown(function(){ URLtoTabTitle.removeMenu();});
  13.  
  14.         this.URLtoTabTitleInit = function()
  15.         {
  16.             this.dump('URLtoTabTitleInit', debugingThisFile);
  17.  
  18.             this.addMenu();
  19.         }
  20.         //adds the menuitem to the tab context menu
  21.         this.addMenu = function ()
  22.         {
  23.             this.dump('addMenu', debugingThisFile);
  24.             
  25.             this.tabContextMenu().appendChild(this.getElement('url-to-tab-title'));
  26.         };
  27.         //remove the menuitem from the tab context menu
  28.         this.removeMenu = function()
  29.         {
  30.             this.dump('removeMenu', debugingThisFile);
  31.             this.removeElement(this.getElement('url-to-tab-title'));
  32.         }
  33.         this.switch = function(item)
  34.         {
  35.             if(item.getAttribute('checked') == 'true')
  36.             {
  37.                 this.dump('switch:checked:true', debugingThisFile);
  38.                 this.initListeners();
  39.                 this.setTitlesTabs();
  40.             }
  41.             else
  42.             {
  43.                 this.dump('switch:checked:false', debugingThisFile);
  44.                 this.removeListeners();
  45.                 this.setTitlesTabsUndo();
  46.             }
  47.         }
  48.         this.setTitlesTabs = function ()
  49.         {
  50.             this.dump('setTitlesTabs', debugingThisFile);
  51.  
  52.             var tabCount = this.tabCount();
  53.             for (var a=0;a<tabCount;a++)
  54.             {
  55.                 var aTab = gBrowser.mTabContainer.childNodes[a];
  56.                 var aURL = this.decodeUTF8Recursive(this.removeWWW(this.removeSchema(this.tabGetLocation(aTab))));
  57.                     if(aURL != '' && aURL != 'about:blank')
  58.                         aTab.setAttribute('label', aURL);
  59.             }
  60.         };
  61.         this.setTitlesTabsUndo = function()
  62.         {
  63.             this.dump('setTitlesTabsUndo', debugingThisFile);
  64.  
  65.             var tabCount = this.tabCount();
  66.             for (var a=0;a<tabCount;a++)
  67.             {
  68.                 var aTab = gBrowser.mTabContainer.childNodes[a];
  69.                 var aTitle = this.documentGetTitleFromTab(aTab);
  70.                     if(aTitle!='')
  71.                         aTab.setAttribute('label', aTitle);
  72.             }
  73.         };
  74.         this.setTitleDoc = function (aDoc)
  75.         {
  76.             this.dump('setTitleDoc', debugingThisFile);
  77.             
  78.             var aTab = this.tabGetFromDocument(aDoc);
  79.             var aURL = this.decodeUTF8Recursive(this.removeWWW(this.removeSchema(this.documentGetLocation(aDoc))));
  80.                 if(aURL != '' && aURL != 'about:blank')
  81.                     aTab.setAttribute('label', aURL );
  82.         };
  83.  
  84.     return null;
  85.  
  86. }).apply(URLtoTabTitle);
  87.